<template>
	<view class="page">
		<view class="bar_info" :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class="title_bar">
				<view class="title_bar_left" @tap.stop="handleJump" data-type="BACK">
					<image class="title_bar_left_icon" :src='STATIC_URL+"5.png"'></image>
				</view>
				<view class="title_bar_center">
					订单详情
				</view>
				<view class="title_bar_right"></view>
			</view>
		</view>
		<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
		<view class="loading_css" v-if="isShow">
			<u-loading size="36" color="#41AF36"></u-loading>
			<view class="loading_text">加载中</view>
		</view>
		<template v-else>
			<view class="order_status flex justify-between">
				<view class="status_le flex align-center">
					<image :src='STATIC_URL+"2.png"' mode=""></image>
					<text v-if="detailsInfo.status == 3">异常处理</text>
					<text v-if="detailsInfo.status == 7">订单退货</text>
				</view>
				<view class="status_ri">
					<image :src='STATIC_URL+"37.png"' mode=""></image>
				</view>
			</view>
			<view class="return_price flex align-center justify-between">
				<view class="flex align-center" v-if="detailsInfo.status == 3">
					<text class="return_price_1">异常总金额：</text>
					<text class="return_price_2" v-if="user.is_show_price == 1">￥{{detailsInfo.total_lose_price}}</text>
					<text class="return_price_2" v-else>￥0</text>
				</view>
				<view class="flex align-center" v-if="detailsInfo.status == 7">
					<text class="return_price_1">退货总金额：</text>
					<text class="return_price_2" v-if="user.is_show_price == 1">￥{{detailsInfo.total_return_price}}</text>
					<text class="return_price_2" v-else>￥0</text>
				</view>
			</view>
			<view class="shop_info">
				<view class="shop_item" v-for="(item, index) in goods" :key="index">
					<view class="flex">
						<view class="shop_img">
							<u-lazy-load :image="item.product_image" img-mode="aspectFill" height="140"
								border-radius="8"></u-lazy-load>
						</view>
						<view class="information">
							<view class="flex">
								<view class="shop_name">{{item.product_name}}</view>
							</view>
							<view class="shop_price flex align-center">
								<image :src='STATIC_URL+"38.png"' mode=""></image>
								<text class="flex align-center">
									<text>{{Number(item.count)}}</text>
									<text>{{filterDictionary(item.product_unit)}}</text>
									<text class="specification">规格：{{item.specification ? item.specification : '无'}}</text>
								</text>
							</view>
							<view class="flex align-center justify-end" style="margin-top: 10rpx;">
								<view class="btn_view" v-if="item.lose_status == 0" @tap.stop="goDeclaration(index)">
									<text>申请异常</text>
								</view>
								<view class="btn_view" v-if="item.return_status == 0" @tap.stop="goReturn(index)">
									<text>申请退货</text>
								</view>
							</view>
						</view>
					</view>
					<template v-if="item.lose_status > 0">
						<view class="status_text flex align-center justify-between">
							<view class="shop_price flex align-center">
								<text>
									<text>异常金额：</text>
									<text v-if="user.is_show_price == 1">￥{{item.lose_price}}</text>
									<text v-else>￥0</text>
								</text>
							</view>
							<view class="shop_price flex align-center">
								<text>异常数量：{{Number(item.lose_count)}}{{filterDictionary(item.product_unit)}}</text>
							</view>
						</view>
						<view class="status_text flex align-center justify-between">
							<view class="flex align-center" v-if="item.lose_status > 0">
								<text>异常审核状态：</text>
								<text v-if="item.lose_status == 1">审核通过</text>
								<text v-if="item.lose_status == 2">审核中</text>
								<text v-if="item.lose_status == 3">审核拒绝</text>
							</view>
							<view class="flex align-center justify-end"
								v-if="item.lose_status == 3">
								<view class="btn_view" @tap.stop="goDeclaration(index)">
									<text v-if="item.lose_status == 3">重新申请</text>
								</view>
							</view>
						</view>
						<view class="status_text" style="color: red;" v-if="item.lose_status == 3">
							<text>异常拒绝原因：</text>
							<text>{{item.lose_reject_remarks}}</text>
						</view>
					</template>
					
					<template v-if="item.return_status > 0">
						<view class="status_text flex align-center justify-between">
							<view class="shop_price flex align-center">
								<text>
									<text>退货金额：</text>
									<text v-if="user.is_show_price == 1">￥{{item.return_price}}</text>
									<text v-else>￥0</text>
								</text>
							</view>
							<view class="shop_price flex align-center">
								<text>退货数量：{{Number(item.return_num)}}{{filterDictionary(item.product_unit)}}</text>
							</view>
						</view>
						
						<view class="status_text flex align-center justify-between">
							<view class="flex align-center" v-if="item.return_status > 0">
								<text>退货审核状态：</text>
								<text v-if="item.return_status == 1">审核通过</text>
								<text v-if="item.return_status == 2">审核中</text>
								<text v-if="item.return_status == 3">审核通过</text>
								<text v-if="item.return_status == 4">审核拒绝</text>
							</view>
							<view class="flex align-center justify-end"
								v-if="item.return_status == 4">
								<view class="btn_view" @tap.stop="goReturn(index)">
									<text v-if="item.return_status == 4">重新申请</text>
								</view>
							</view>
						</view>
						
						<view class="status_text" style="color: red;" v-if="item.return_status == 4">
							<text>退货拒绝原因：</text>
							<text>{{item.return_reject_remarks}}</text>
						</view>
					</template>
				</view>
			</view>

			<view class="content_bg" v-if="receipt_image.length > 0" style="padding-bottom: 0;">
				<view class="content_title">收货凭据</view>
				<view class="receipt_image">
					<image v-for="(v, k) in receipt_image" :key="k" :src="v" mode="aspectFill" @tap.stop="previewImage(k)"></image>
				</view>
			</view>

			<view class="content_bg">
				<view class="content_title">订单信息</view>
				<view class="content_item flex align-center justify-between">
					<view class="content_item_le">订单编号</view>
					<view class="content_item_ri">{{detailsInfo.order_no}}</view>
				</view>
				<view class="content_item flex align-center justify-between">
					<view class="content_item_le">下单时间</view>
					<view class="content_item_ri">{{detailsInfo.created_at}}</view>
				</view>
				<view class="content_item flex align-center justify-between">
					<view class="content_item_le">申请时间</view>
					<view class="content_item_ri">{{detailsInfo.updated_at}}</view>
				</view>
				<view class="content_item flex align-center justify-between">
					<view class="content_item_le">备注</view>
					<view class="content_item_ri">{{detailsInfo.remark ? detailsInfo.remark : '无'}}</view>
				</view>
			</view>
		</template>


	</view>
</template>

<script>
	import {
		validate
	} from '@/common/utils/validate.js'
	export default {
		data() {
			return {
				image: '/static/index/3.png',
				isShow: true,
				order_no: "",
				detailsInfo: {},
				goods: [],
				receipt_image: [],
				user: {},
			}
		},
		onLoad(options) {
			let {
				order_no
			} = options;
			if (order_no !== undefined) this.order_no = order_no;
		},
		onShow() {
			this.user = global.userInfo;
			this.getDetails();
		},
		methods: {
			getDetails() {
				this.$api.get(global.apiUrls.gylOrderDetails, {
					order_id: this.order_no
				}).then(res => {
					// console.log(res);
					this.isShow = false;
					if (res.data.code == 200) {
						this.detailsInfo = res.data.data;
						if (this.detailsInfo.receipt_image) {
							this.receipt_image = this.detailsInfo.receipt_image.split(',');
						}
						this.goods = res.data.data.goods;
					} else {
						this.$message.info(res.data.message);
					}
				})
			},
			// 提报异常
			goDeclaration(index) {
				global.orderShop = this.goods[index];
				uni.navigateTo({
					url: '/pages/my/abnormalDeclaration'
				})
			},
			// 提交退货
			goReturn(index) {
				global.orderShop = this.goods[index];
				uni.navigateTo({
					url: '/pages/my/returnGoods'
				})
			},
			// 预览收获凭据
			previewImage(index) {
				let _this = this;
				uni.previewImage({
					current: index, // 当前显示图片索引
					urls: _this.receipt_image // 需要预览的图片http链接列表
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		min-height: calc(100vh - var(--window-bottom));
		background: url(https://www.shiyaocanyin.com/images/8.png) no-repeat #f5f5f5;
		background-size: 100% auto !important;

		.bar_info {
			width: 750rpx;
			height: 88rpx;
			overflow: hidden;
			z-index: 10;
			position: fixed;
			top: 0rpx;
			background: url(https://www.shiyaocanyin.com/images/8.png) no-repeat;
			background-size: 100% auto !important;

			.title_bar {
				padding: 0 32rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.title_bar_left {
					width: 50rpx;

					.title_bar_left_icon {
						width: 18rpx;
						height: 32rpx;
					}
				}

				.title_bar_center {
					line-height: 88rpx;
					font-size: 36rpx;
					font-weight: 400;
				}

				.title_bar_right {
					width: 50rpx;
				}
			}
		}

		.save_btn {
			width: 700rpx;
			height: 80rpx;
			background: #41AF36;
			border-radius: 50rpx;
			font-size: 30rpx;
			font-weight: 500;
			color: #fff;
			text-align: center;
			line-height: 80rpx;
			margin: 120rpx auto 0;
		}
	}

	.status_text {
		font-size: 26rpx;
		color: #999;
		margin-top: 10rpx;
		padding: 0 10rpx;
	}

	.order_status {
		padding: 0 20rpx;

		.status_le {
			transform: translateY(-20rpx);

			image {
				width: 40rpx;
				height: 40rpx;
				margin-right: 16rpx;
			}

			text {
				font-weight: 500;
				font-size: 42rpx;
				color: #3D3D3D;
			}
		}

		.status_ri {
			width: 225rpx;
			height: 225rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}
	}

	.return_price {
		background: #fff;
		padding: 30rpx 20rpx 30rpx 30rpx;
		border-radius: 10rpx;
		margin: -75rpx 20rpx 0;
		position: relative;
		z-index: 5;

		.return_price_1 {
			font-weight: 700;
			font-size: 30rpx;
			color: #3D3D3D;
		}

		.return_price_2 {
			font-weight: 700;
			font-size: 30rpx;
			color: #D43C3B;
		}
	}

	.shop_info {
		background: #fff;
		padding: 30rpx 20rpx 16rpx 30rpx;
		border-radius: 10rpx;
		margin: 20rpx 20rpx 0;

		.shop_item {
			margin-bottom: 20rpx;

			.shop_img {
				width: 140rpx;
				height: 140rpx;
				border-radius: 8rpx;
			}

			/deep/.u-lazy-item {
				width: 140rpx !important;
				height: 140rpx !important;
			}

			.information {
				flex: 1;
				margin: 0 0 0 30rpx;

				.shop_name {
					font-weight: 500;
					font-size: 32rpx;
					color: #3D3D3D;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 1;
					/* 定义显示的行数 */
					overflow: hidden;
					text-overflow: ellipsis;
				}
			}
			.specification {
				font-size: 24rpx;
				color: #999;
				margin-left: 32rpx;
				transform: translateY(5rpx);
			}

			.shop_price {
				margin-top: 8rpx;
				font-weight: 400;
				font-size: 24rpx;
				color: rgba(0, 0, 0, 0.5);

				image {
					width: 24rpx;
					height: 26rpx;
					margin-right: 10rpx;
				}
			}

			.price_info {
				margin-top: 8rpx;

				.price_1 {
					font-weight: 500;
					font-size: 24rpx;
					color: #3D3D3D;
				}

				.price_2 {
					font-weight: 500;
					font-size: 30rpx;
					color: #3D3D3D;
				}
			}

			.return_view {
				width: 100rpx;
				height: 80rpx;
			}

			.return_view_1 {
				width: 80rpx;
				height: 85rpx;
			}
		}

		.merchandise {
			padding: 28rpx 0 18rpx;
			border-bottom: 1px solid rgba(0, 0, 0, 0.1);

			.merchandise_le {
				font-weight: 400;
				font-size: 26rpx;
				color: #3D3D3D;
			}

			.merchandise_ri {
				font-weight: 500;
				font-size: 26rpx;
				color: #000000;
			}
		}

		.shop_amount {
			margin-top: 20rpx;

			.amount_1 {
				font-weight: 500;
				font-size: 26rpx;
				color: #000000;
			}

			.amount_2 {
				font-weight: 500;
				font-size: 26rpx;
				color: #D43C3B;
			}
		}
	}

	.content_bg {
		margin: 20rpx 20rpx 0;
		background: #fff;
		border-radius: 10rpx;
		padding: 30rpx;

		.content_item {
			margin-top: 28rpx;

			.content_item_le {
				font-weight: 400;
				font-size: 26rpx;
				color: rgba(61, 61, 61, 0.5);
			}

			.content_item_ri {
				font-weight: 500;
				font-size: 26rpx;
				color: #000000;
			}
		}
	}

	.receipt_image {
		margin-top: 28rpx;
		overflow: hidden;
		image {
			float: left;
			width: 148rpx;
			height: 148rpx;
			border-radius: 8rpx;
			margin: 0 16rpx 16rpx 0;
		}
		image:nth-child(4n+4) {
			margin-right: 0;
		}
	}


	.content_title {
		font-weight: 500;
		font-size: 36rpx;
		color: #3D3D3D;
		padding-bottom: 18rpx;
		border-bottom: 1px solid rgba(0, 0, 0, 0.1);
	}

	.details_btn {
		position: fixed;
		bottom: 0;
		width: 100%;
		height: 110rpx;
		padding: 15rpx 30rpx;
		background: #f5f5f5;

		.btn_1 {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 330rpx;
			height: 80rpx;
			background: #41AF36;
			border-radius: 50rpx;
			font-weight: 500;
			font-size: 30rpx;
			color: #fff;
		}
	}

	.codeLogin_fd1_1_c2 {
		font-size: 26rpx;
		color: #41AF36;
		font-weight: 500;
		margin-left: 30rpx;
	}

	.btn_view {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 120rpx;
		height: 50rpx;
		background: #41AF36;
		border-radius: 10rpx;
		font-size: 22rpx;
		color: #fff;
		margin-left: 20rpx;
	}
</style>